package io.eleKing.boot.weather.controller;

import io.eleKing.boot.auth.annotation.Permission;
import io.eleKing.boot.common.enums.SysLogType;
import io.eleKing.boot.framework.annotation.Log;
import io.eleKing.boot.framework.page.Paging;
import io.eleKing.boot.framework.response.ApiResult;
import io.eleKing.boot.weather.dto.WeatherHourDataDto;
import io.eleKing.boot.weather.query.WeatherHourDataQuery;
import io.eleKing.boot.weather.service.WeatherHourDataService;
import io.eleKing.boot.weather.vo.WeatherHourDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  控制器
 *
 * @author eleKing
 * @since 2025-04-15
 */
@Slf4j
@RestController
// 
@RequestMapping("/admin/weatherHourData")
public class WeatherHourDataController {

    @Autowired
    private WeatherHourDataService weatherHourDataService;

    /**
     * 添加null
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    // 添加null
    @PostMapping("/addWeatherHourData")
    @Permission("weather:hour:data:add")
    public ApiResult addWeatherHourData(@Valid @RequestBody WeatherHourDataDto dto) {
        log.info("添加null：{}", dto);
        boolean flag = weatherHourDataService.addWeatherHourData(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改null
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    // 修改null
    @PostMapping("/updateWeatherHourData")
    @Permission("weather:hour:data:update")
    public ApiResult updateWeatherHourData(@Valid @RequestBody WeatherHourDataDto dto) {
        log.info("修改null：{}", dto);
        boolean flag = weatherHourDataService.updateWeatherHourData(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除null
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    // 删除null
    @PostMapping("/deleteWeatherHourData/{id}")
    @Permission("weather:hour:data:delete")
    public ApiResult deleteWeatherHourData(@PathVariable Long id) {
        log.info("删除null：{}", id);
        boolean flag = weatherHourDataService.deleteWeatherHourData(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取null详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    // 获取null详情
    @PostMapping("/getWeatherHourData/{id}")
    @Permission("weather:hour:data:info")
    public ApiResult<WeatherHourDataVo> getWeatherHourData(@PathVariable Long id) {
        log.info("获取null详情：{}", id);
        WeatherHourDataVo weatherHourDataVo = weatherHourDataService.getWeatherHourDataById(id);
        return ApiResult.success(weatherHourDataVo);
    }

    /**
     * 获取null分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    // 获取null分页列表
    @PostMapping("/getWeatherHourDataPage")
    @Permission("weather:hour:data:page")
    public ApiResult<WeatherHourDataVo> getWeatherHourDataPage(@Valid @RequestBody WeatherHourDataQuery query) {
        log.info("获取null分页列表：{}", query);
        Paging<WeatherHourDataVo> paging = weatherHourDataService.getWeatherHourDataPage(query);
        return ApiResult.success(paging);
    }

}
